package com.leyou.item.web;

import com.leyou.item.dto.SpecGroupDTO;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.dto.SpuDetailDTO;
import com.leyou.item.entity.SpuDetail;
import com.leyou.item.service.ParamService;
import com.leyou.item.service.SpecGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/spec")
public class SpecController {
    @Autowired
    private SpecGroupService specGroupService;
    @Autowired
    private ParamService paramService;


    //根据id来查规格组
    @GetMapping("/groups/of/category")
    public ResponseEntity<List<SpecGroupDTO>> queryGroupByCategory(
            @RequestParam("id")Long cid){

        return ResponseEntity.ok(this.specGroupService.queryGroupByCategory(cid));
    }

    //新增商品
    @GetMapping("/params")
    public ResponseEntity<List<SpecParamDTO>> paramQuery(
            @RequestParam(value = "categoryId", required = false) Long categoryId,
            @RequestParam(value = "groupId", required = false) Long groupId
    ) {

        return ResponseEntity.ok(this.paramService.paramQuery(categoryId, groupId));
    }

    //根据spuId查询规格组以及规格组内参数集合
    @GetMapping("/list/of/category")
    public  ResponseEntity<List<SpecGroupDTO>> querySpecList(
            @RequestParam("id") Long cid
    ){
        return ResponseEntity.ok(this.specGroupService.querySpecList(cid));
    }
}
